using System.Collections;
using System;
using System.Collections.Generic;
using Generics;
class Program
{
    static void Main()
    {
        ArrayList list = new ArrayList();
        list.Add(44); // boxing -- convert a value type to a reference type
        int i1 = (int)list[0]; // unboxing -- convert a reference type to a value type
        Console.WriteLine($"list[0] = {i1}"); // unboxing
        foreach (int i2 in list)
        {
            Console.WriteLine(i2); // unboxing
        }

        List<int> list2 = new List<int>();
        list2.Add(33);
        int i3 = list2[0];

        foreach (int i4 in list2)
        {
            Console.WriteLine(i4);
        }

        var list3 = new MyLinkedList();
        list3.AddLast(3);
        list3.AddLast(4);
        // list3.AddLast("6"); // 遍历时会导致异常

        foreach (int i in list3)
        {
            Console.WriteLine(i); // 异常
        }

        var listviewdatas = new List<List<string>>();

        var str_list0 = new List<string>() {
            "hello",
            "world",
        };

        var str_list1 = new List<string>() {
            "good",
            "night",
        };
        var str_list2 = new List<string>() {
            "how",
            "are",
            "you"
        };

        listviewdatas.Add(str_list0);
        listviewdatas.Add(str_list1);
        listviewdatas.Add(str_list2);

        var listviewObject = listviewdatas.ToArray();
        PrintList(listviewObject);
    }

    static void PrintList(object[] datas) 
    {
        var firstData = datas[0];
        IList objList = (IList)firstData;  
        int count = objList.Count;
       
       for (int i = 0; i < count; i++)
       {
            Console.WriteLine($"{i} --> {objList[i]}");
       }
    }
}